<template>
  <el-menu
      :default-active="activeMenu"
      class="el-menu-vertical-demo"
      :collapse="isCollapse"
      :unique-opened='false'
      router
  >
    <el-menu-item :index="item.path" v-for="item in noChildren" :key="item.path">
      <el-icon>
        <component :is="item.meta.icon"/>
      </el-icon>
      <template #title>{{ item.meta.tittle }}</template>
    </el-menu-item>

    <el-sub-menu :index="item.path" v-for="item in hasChildren" :key="item.path">
      <template #title>
        <el-icon>
          <component :is="item.meta.icon"/>
        </el-icon>
        <span>{{ item.meta.tittle }}</span>
      </template>
      <el-menu-item-group :index="items.path" v-for="items in item.children" :key="items.path">
        <el-menu-item :index="items.path">
          <el-icon>
            <component :is="items.meta.icon"/>
          </el-icon>
          <template #title>{{ items.meta.tittle }}</template>
        </el-menu-item>
      </el-menu-item-group>
    </el-sub-menu>
  </el-menu>
</template>

<script lang="ts" setup>
import {computed} from "vue";
import {useStore} from "vuex";
import {useRoute} from "vue-router";

const route=useRoute()
const store = useStore()
store.commit('GET_MENU')

const isCollapse=computed(()=>store.getters.isCollapse)
const activeMenu=computed(()=>route.path)
const noChildren=computed(()=>store.getters.noChildren)
const hasChildren=computed(()=>store.getters.hasChildren)
</script>

<style scoped lang="less">
.el-menu-vertical-demo {
  height: 100%;

  &:not(.el-menu--collapse) {
    width: 200px;
  }
}
</style>
